import Link from "next/link"; import { CopyButton } from "@/components/copy-button"; import { PopiartApiError, getBudgetSummary, getBudgetUsage, getPopiartEndpoint, getViewerSession } from "@/lib/popiart-api"; import { getLiveCopy } from "@/lib/live-copy"; import { type Locale } from "@/lib/site-content"; export const dynamic = "force-dynamic"; function formatNumber(locale: Locale, value: number) { return new Intl.NumberFormat(locale === "zh" ? "zh-CN" : "en-US").format(value); } function maskSecret(value?: string) { if (!value) { return "Unavailable"; } if (value.length <= 10) { return value; } return `${value.slice(0, 8)} • • • • ${value.slice(-4)}`; } function formatError(error: unknown) { if (error instanceof PopiartApiError) { return error.message; } if (error instanceof Error) { return error.message; } return String(error); } export default async function ConsolePage({ params, }: { params: Promise<{ locale: string }>; }) { const { locale } = await params; const typedLocale = locale as Locale; const liveCopy = getLiveCopy(typedLocale); const session = await getViewerSession(); const isZh = typedLocale === "zh"; const pageTitle = isZh ? "控制台" : "Console"; const pageSubtitle = isZh ? "管理产品层密钥、查看用量、快速接入 CLI" : "Manage product-layer keys, usage, and quick CLI onboarding."; const remainingLabel = isZh ? "剩余 Credit" : "Remaining credits"; const remainingHint = isZh ? "总计可用额度" : "Total available quota"; const usedLabel = isZh ? "已使用" : "Used"; const usedHint = isZh ? "本月累计消耗" : "Consumed this month"; const callsLabel = isZh ? "调用次数" : "API calls"; const callsHint = isZh ? "本月 CLI / API 调用" : "CLI / API calls this month"; const keysTitle = isZh ? "API 密钥" : "API keys"; const quickTitle = isZh ? "快速安装指令" : "Quick install commands"; const quickBody = isZh ? "把下面这段命令复制到终端,完成 CLI 安装、登录和验证。" : "Copy these commands into your terminal to install the CLI, sign in, and verify the workflow."; const sessionKeyLabel = "POPIART_SESSION_KEY"; const endpointLabel = "POPIART_ENDPOINT"; const copyLabel = isZh ? "复制" : "Copy"; const copiedLabel = isZh ? "已复制" : "Copied"; const loginCta = isZh ? "去登录" : "Sign in"; const docsCta = isZh ? "查看文档" : "Open docs"; if (!session) { return (
{pageSubtitle}
{liveCopy.console.unauthenticatedBody}
{pageSubtitle}
{quickBody}
{quickStart}